//
//  WLVideoPlayManager.m
//  WanLian
//
//  Created by 123456 on 2018/12/11.
//  Copyright © 2018 wanlian. All rights reserved.
//

#import "WLVideoPlayManager.h"
#import <MediaPlayer/MediaPlayer.h>
@implementation WLVideoPlayManager
-(void)openmovieWithVideoURL:(NSString *)url

{
    if (url.length == 0) {
        return;
    }
     MPMoviePlayerViewController *movie = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:url]];
    
     [movie.moviePlayer prepareToPlay];
    
     [self.currentController presentMoviePlayerViewControllerAnimated:movie];
    
     [movie.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
    
     [movie.view setBackgroundColor:[UIColor clearColor]];
    
    
     [movie.view setFrame:self.currentController.view.bounds];
    
     [[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(movieFinishedCallback:)
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:movie.moviePlayer];
    
    MPMoviePlayerController *player = [movie moviePlayer];
    [player play];
    
}
-(void)movieFinishedCallback:(NSNotification*)notify{
     // 视频播放完或者在presentMoviePlayerViewControllerAnimated下的Done按钮被点击响应的通知。
    
     MPMoviePlayerController* theMovie = [notify object];
     [[NSNotificationCenter defaultCenter]removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:theMovie];
    
    
     [self.currentController dismissMoviePlayerViewControllerAnimated];
}
-(void)openmovieWithLocal:(NSString *)url

{
    if (url.length == 0) {
        return;
    }
    MPMoviePlayerViewController *movie = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:url]];
    
    [movie.moviePlayer prepareToPlay];
    
    [self.currentController presentMoviePlayerViewControllerAnimated:movie];
    
    [movie.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
    
    [movie.view setBackgroundColor:[UIColor clearColor]];
    
    
    [movie.view setFrame:self.currentController.view.bounds];
    
    [[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(movieFinishedCallback:)
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:movie.moviePlayer];
    
    MPMoviePlayerController *player = [movie moviePlayer];
    [player play];
}

-(void)openmovieWithLocalMediaURL:(NSURL *)url

{
    if (url.path.length == 0) {
        return;
    }
    MPMoviePlayerViewController *movie = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    
    [movie.moviePlayer prepareToPlay];
    
    [self.currentController presentMoviePlayerViewControllerAnimated:movie];
    
    [movie.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
    
    [movie.view setBackgroundColor:[UIColor clearColor]];
    
    
    [movie.view setFrame:self.currentController.view.bounds];
    
    [[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(movieFinishedCallback:)
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:movie.moviePlayer];
    
    MPMoviePlayerController *player = [movie moviePlayer];
    [player play];
}

@end
